package com.jinzht.web.filter;

import javax.interceptor.Interceptor;
import javax.jws.soap.InitParam;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.jinzht.tools.Config;

public class LogInterceptor implements HandlerInterceptor {
	@Override
	public void afterCompletion(HttpServletRequest arg0,
			HttpServletResponse response, Object arg2, Exception arg3)
			throws Exception {
		// TODO Auto-generated method stub

	}

	@Override
	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1,
			Object arg2, ModelAndView arg3) throws Exception {
		// TODO Auto-generated method stub

	}

	@Override
	public boolean preHandle(HttpServletRequest hrequest,
			HttpServletResponse hresponse, Object arg2) throws Exception {
		// 获取session会话
		HttpSession session = hrequest.getSession(true);

		// 输出请求信息
		System.out.println("Filter 截获到用户倾听求地址:  " + hrequest.getServletPath());

		// 后台系统监听
		if (hrequest.getServletPath().contains("/manager/")
				&& !hrequest.getServletPath().contains("index")) {
			if (!hrequest.getServletPath().contains("adminLogin")) {
				if (!hrequest.getServletPath().contains("ScheduledProfile") && !hrequest.getServletPath().contains("auditOrderRecords") && !hrequest.getServletPath().contains("BackUpDataBase")) {
					if (session.getAttribute("adminId") == null) {
						System.out.println("Filter 截获到用户状态:  已失效1");
						hresponse.sendRedirect(Config.STRING_SYSTEM_ADDRESS);
						return false;
					}
				}
			}
		}
		return true;
	}

}
